import 'package:enter_prise_web/common/constants.dart';
import 'package:enter_prise_web/page/index/index_controller.dart';
import 'package:enter_prise_web/page/work/work_controller.dart';
import 'package:enter_prise_web/page/work/work_page.dart';
import 'package:enter_prise_web/widgets/filter_view.dart';
import 'package:enter_prise_web/widgets/setting_form.dart';
import 'package:enter_prise_web/widgets/side_menu.dart';
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:get/get.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';

class MainAndroid extends StatefulWidget {
  const MainAndroid({super.key});
  @override
  State<MainAndroid> createState() => _MainAndroidState();
}

class _MainAndroidState extends State<MainAndroid> {
  final IndexController _indexController = Get.find();
  final WorkController workController = Get.find();
  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Obx(
          () => Scaffold(
            resizeToAvoidBottomInset: false,
            key: _scaffoldKey,
            appBar: AppBar(
                title: Obx(() => Text(_indexController.title.value)
                    .animate(effects: transitonIn)),
                actions: [
                  if (_indexController.currentIndex.value == 0) Container(),
                  if (_indexController.currentIndex.value == 1)
                    IconButton(
                      icon: const Icon(Icons.add),
                      onPressed: () {
                        showCupertinoModalBottomSheet(
                            context: context,
                            builder: (context) => const settingForm());
                      },
                    ),
                  if (_indexController.currentIndex.value == 3) Container(),
                  if (_indexController.currentIndex.value == 4) Container(),
                ]),
            drawer: ConstrainedBox(
                constraints: const BoxConstraints(maxWidth: 250),
                child: SideMenu()),
            body: Material(
              color: kDefaualtBgColor,
              child: PageView(
                physics: const NeverScrollableScrollPhysics(),
                controller: _indexController.pageController,
                children: _indexController.pageViews,
              ),
            ),
          ),
        ),
        GetBuilder<IndexController>(
          id: "filterView",
          builder: (controller) {
            if (controller.isShowFilter == false) return Container();
            return GestureDetector(
              onTap: () {
                //取消展示
                controller.makeFilterIsNotShow();
              },
              child: Container(
                color: Colors.black45.withOpacity(0.3),
                child: FilterView(
                  indexController: controller,
                  callBack: (FilterType type) {
                    setState(() {
                      controller.filterType = type;
                    });
                    //通过FilterType查询记录
                    workController.updateData(controller.filterType);
                  },
                ),
              ),
            );
          },
        )
      ],
    );
  }
}
